
// 将数据库的相关操作封装在该模块中
var mongoose = require('mongoose')

mongoose.connect('mongodb://localhost:27017/ManagerBook')

var db = mongoose.connection

db.on('open',()=>{
  console.log('连接成功');
})
db.on('error',()=>{
  console.log('连接失败');
})

// 定义存储表
// 1.定义用户的存储表
var UserSchema = mongoose.Schema({
  username:String,
  psw:String,
  phone:Number
},{collection:'userinfo'})

var User = mongoose.model('User',UserSchema)


// 2.定义书籍的存储表
var BookSchema = mongoose.Schema({
  bookname:String,
  author:String,
  price:Number,
  count:Number,
  num:Number,
  pic:String
})
var Book = mongoose.model('Book',BookSchema)
// 定义购物车的储存表
var CarSchema=mongoose.Schema({
  bookname:String,
  author:String,
  price:Number,
  nowprice:Number,
  sum:Number,
  pic:String,
  username:String
})
var Car=mongoose.model('ShopCar',CarSchema)
module.exports={User,Book,Car}


